package com.southwind.aop;

import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect     //说明该类是切面类
@Component  //将该类的对象注入到ioc容器中
public class LoggerAspect {
	
	//before表示方法执行的具体位置和时机
	@Before(value = "execution(public int com.southwind.utils.impl.CalImpl.*(..)) ")
	public void before(JoinPoint joinPoint) {
		//获取方法名
		String name = joinPoint.getSignature().getName();
		//获取参数
		String args = Arrays.toString(joinPoint.getArgs());
		System.out.println(name+"方法的参数是"+args);
	}
	
	@After(value = "execution(public int com.southwind.utils.impl.CalImpl.*(..)) ")
	public void after(JoinPoint joinPoint) {
		//获取方法名
		String name = joinPoint.getSignature().getName();
		System.out.println(name+"方法执行完毕");
	}
	
	@AfterReturning(value="execution(public int com.southwind.utils.impl.CalImpl.*(..))",returning = "result1")
	public void afterReturning(JoinPoint joinPoint,Object result1) {
		//获取方法名
		String name = joinPoint.getSignature().getName();
		System.out.println(name+"方法的结果是"+result1);
	}
	
	@AfterThrowing(value = "execution(public int com.southwind.utils.impl.CalImpl.*(..))",throwing = "exception")
	public void afterThrowing(JoinPoint joinPoint,Exception exception) {
		//获取方法名
		String name = joinPoint.getSignature().getName();
		System.out.println(name+"方法抛出异常"+exception);
	}
	

}
